package com.cyt.web.controller.wx;

import cn.hutool.core.util.StrUtil;
import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.base.util.BaseConstant;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.web.controller.base.BaseController;
import com.cyt.wx.model.po.WxApplyUse;
import com.cyt.wx.model.po.WxApplyUseCategory;
import com.cyt.wx.model.po.WxIndustryCategory;
import com.cyt.wx.model.vo.WxApplyUseCategoryVo;
import com.cyt.wx.model.vo.WxApplyUseVo;
import com.cyt.wx.model.vo.WxIndustryCategoryVo;
import com.cyt.wx.service.WxApplyUseCategoryService;
import com.cyt.wx.service.WxApplyUseService;
import com.cyt.wx.service.WxIndustryCategoryService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 应用信息-应用信息控制层
 *
 * @author shengQiang Yu
 * @date 2019-8-8 8:45:12
 */
@RestController
public class WxApplyUseController extends BaseController {

    @Resource
    private WxIndustryCategoryService wxIndustryCategoryService;
    @Resource
    private WxApplyUseCategoryService wxApplyUseCategoryService;
    @Resource
    private WxApplyUseService wxApplyUseService;

    /**
     * 统一跳转
     *
     * @param model 数据模型
     * @return Model
     * @author shengQiang Yu
     * @date 2019-8-8 8:45:12
     */
    @RequestMapping("/wx/wxapplyuse/*")
    public Model goPage(Model model) {
        return model;
    }

    /**
     * 分页查询
     *
     * @param wxApplyUseVo 接受参数对象
     * @param page 当前页面
     * @param limit 页面数量
     * @return ReturnResult
     * @author shengQiang Yu
     * @date 2019-8-8 8:45:12
     */
    @BaseLog(module = "应用信息", classz = "应用信息", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wx/wxapplyuse/page", method = RequestMethod.POST)
    public ReturnResult page(WxApplyUseVo wxApplyUseVo, int page, int limit) {
        return wxApplyUseService.page(wxApplyUseVo, page, limit);
    }

    /**
     * 跳转添加或编辑界面
     *
     * @param id 主键
     * @return ReturnResult
     * @author shengQiang Yu
     * @date 2019-8-8 8:45:12
     */
    @BaseLog(module = "应用信息", classz = "应用信息", methods = "跳转添加或编辑界面", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wx/wxapplyuse/getEdit", method = RequestMethod.GET)
    public ModelAndView getEdit(String id) {
        ModelAndView view = new ModelAndView("/wx/wxapplyuse/wxApplyUseEdit");
        WxIndustryCategoryVo wxIndustryCategoryVo = new WxIndustryCategoryVo();
        wxIndustryCategoryVo.setStatus(BaseConstant.BASE_STATUS_YES);
        wxIndustryCategoryVo.setIndexStatus(BaseConstant.WEBSITE_INDEX_STATUS_YES);
        wxIndustryCategoryVo.setRemoveTag(BaseConstant.REMOVE_TAG_NO);
        List<WxIndustryCategory> categoryList = wxIndustryCategoryService.listExample(wxIndustryCategoryVo);
        if (StrUtil.isNotEmpty(id)) {
            WxApplyUseCategoryVo wxApplyUseCategoryVo = new WxApplyUseCategoryVo();
            wxApplyUseCategoryVo.setApplyUseId(id);
            wxApplyUseCategoryVo.setRemoveTag(BaseConstant.REMOVE_TAG_NO);
            List<WxApplyUseCategory> applyUseCategoryList = wxApplyUseCategoryService.findList(wxApplyUseCategoryVo);
            view.addObject(wxApplyUseService.selectByPrimaryKey(id));
            view.addObject("applyUseCategoryList", applyUseCategoryList);
        }
        view.addObject("categoryList", categoryList);
        return view;
    }

    /**
     * 保存或更新
     *
     * @param request 请求对象
     * @param wxApplyUseVo 接受参数对象
     * @return ReturnResult
     * @author shengQiang Yu
     * @date 2019-8-8 8:45:12
     */
    @BaseLog(module = "应用信息", classz = "应用信息", methods = "保存或更新对象", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wx/wxapplyuse/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(HttpServletRequest request, WxApplyUseVo wxApplyUseVo) {
        return wxApplyUseService.addOrUpdate(wxApplyUseVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件逻辑删除
     *
     * @param request 请求对象
     * @param wxApplyUseVo 接受参数对象
     * @return ReturnResult
     * @author shengQiang Yu
     * @date 2019-8-8 8:45:12
     */
    @BaseLog(module = "应用信息", classz = "应用信息", methods = "逻辑删除对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wx/wxapplyuse/remove", method = RequestMethod.GET)
    public ReturnResult remove(HttpServletRequest request, WxApplyUseVo wxApplyUseVo) {
        return wxApplyUseService.remove(wxApplyUseVo, acceptCurrentUser(request));
    }

    /**
     * 对象查询
     *
     * @param wxApplyUseVo 接受参数对象
     * @return ReturnResult
     * @author shengQiang Yu
     * @date 2019-8-8 8:45:12
     */
    @BaseLog(module = "应用信息", classz = "应用信息", methods = "对象查询", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wx/wxapplyuse/selectOne", method = RequestMethod.POST)
    public ReturnResult selectOne(WxApplyUseVo wxApplyUseVo) {
        WxApplyUse wxApplyUse = new WxApplyUse();
        wxApplyUse.setId(wxApplyUseVo.getId());
        return new ReturnResult(wxApplyUseService.selectOne(wxApplyUse));
    }
}